#include <bits/stdc++.h>
using namespace std;
const int maxr = 10+2;
const int maxc = 1000+10;
const int INF = 0x3f3f3f3f;
int A[maxr][maxc], dp[maxr][maxc], best[maxr][maxc];
int m, n;

int DP(int r, int c, int sr){
    int& ans = dp[r][c];
    if(ans > 0) return ans;
    if(c == n) return ans = A[r][c];
    ans = INF;


    return ans;
}
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    while(cin >> m >> n){
        memset(dp, 0, sizeof(dp));
        memset(best, 0, sizeof(best));
        for (int r = 1; r <= m; ++r) {
            for (int c = 1; c <= n; ++c) {
                cin >> A[r][c];
            }
        }
        int ans = INF, br = 0;
        for (int c = n; c >=1 ; --c) {
            for (int r = 1; r <= m; ++r) {
                if(c == n) dp[r][c] = A[r][c];
                else{
                    int up = r==1? m : r-1;
                    int down = r==m? 1 : r+1;
                    int R[3] = {up, r, down};
                    sort(R, R+3);
                    dp[r][c] = INF;
                    for (int i = 0; i < 3; ++i) {
                        int rr = R[i];
                        int v = dp[rr][c+1] + A[r][c];
                        if(v < dp[r][c]) dp[r][c] = v, best[r][c] = rr;
                    }
                }
                if(c==1 && dp[r][c]<ans) ans = dp[r][c], br = r;
            }
        }
        int out = br;
        cout << out;
        for (int i = 1; i <= n-1; ++i) {
            out = best[out][i];
            cout << " " << out;
        }
        cout << "\n" << ans <<"\n";
    }
    return 0;
}